// pages/search/search.js
const app = getApp()
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  properties: {
    datalist: Array,
    keywords: String,
    placeholder: String,
    title: String,
    addUrl: String
  },
  data: {
    imgUrl: app.globalData.imgUrl,
    datalist: [],
    keywords: '',
    coderid: '',
    placeholder: '',
    name: '',
    title: '取消'
  },
  methods: {
    //历史搜索记录
    confirmInput: function (e) {
      var name = e.detail.value;
      console.log(this.data.keywords, 'name')
      this.triggerEvent("seacherKeywords", name); //触发回调
    },

    //监听搜索框值 
    valInput: function (e) {
      var keywords = e.detail.value;

      this.setData({
        keywords: keywords
      })
    },

    // 取值
    choose: function (e) {
      var seachItem = {
        item: e.currentTarget.dataset.item
      }
      this.triggerEvent("seacherchoose", seachItem); //触发回调
    },

    // //取消
    cancel: function () {
      this.triggerEvent("seacherCancel"); //触发回调
    },

    clearInput(e) {
      console.log(e)
      this.triggerEvent("seacherCancel"); //触发回调
      this.setData({
        keywords: ""
      })
    },
    //新增更多
    toAdd: function (e) {
      var url = e.currentTarget.dataset.url;
      wx.redirectTo({
        url
      })
    }


  }

})